import { useEffect, useRef } from "react";

export default function UseRefCom() {
    const imgRef = useRef<HTMLImageElement>(null);
    // 当组件挂载完毕之后，给img添加样式
    useEffect(() => {
      if (imgRef.current) {
        imgRef.current.style.border = "1px solid red";
      }
    }, []);
  return (
    <div>
      <p>UseRefCom</p>
      <img ref={imgRef} src="https://picsum.photos/500/500" alt="" />
    </div>
  )
}